
<style>
    .description { color: #999; font-size: 13px; }
    .send-item-list li, .send-pet-list li { margin: 8px 0; }
    .send-item-list li .form-control, .send-pet-list li .form-control { margin-right: 2px; }
    .tools-btn { padding: 5px 7px; border-radius: 12px; }
    .div_item_name{float: left;}
    .div_item_id{float: left;}
    form{margin-bottom: 300px;}
</style>

<form method="post" action="/oss/?r=insidePlayer/doAdd">
    <{include file='../common_params.tpl'}>
    <div class="box box-black">
        <div class="box-body">
        	<h5> <i class="fa fa-users"></i>&nbsp;&nbsp;信息</h5>
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>
                
                <tr>
                    <th class="th-label">专服</th>
                    <td>
                        <select class="form-control" name="special_id" id="special_id" style="width: 150px;">
                            <option value="">请选择</option>
                            <{foreach from=$specialList item=item key=key}>
                        		<option value="<{$key}>"><{$item}></option>
                        	<{/foreach}>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">服务器</th>
                    <td>
                        <select class="form-control" name="server_id" id="server_id" style="width: 150px;">
                            <option value="">请选择</option>                            
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">角色名</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="role_name" id="role_name" />
                        <a href="javascript:void(0);" id="check_role" class="btn btn-default">&nbsp;检查角色名</a>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">角色ID</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="role_id" id="role_id" />
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">账号</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="account" id="account" />
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">真实姓名</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="real_name" id="real_name" />
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">职位</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="position" id="position" />
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">是否趣炫</th>
                    <td>
                        <select class="form-control" name="is_qx" id="is_qx" style="width: 100px;">
                            <option value="1">是</option>
                            <option value="2">否</option>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">申请有效期</th>
                    <td>
                        <input type="text" name="ban_date" class="form-control inline time" />
                        <label><input type="checkbox" name="ban_forever" class="simple" id="ban-forever" />永久</label>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">交易元宝数</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="trade_gold" id="trade_gold" />
                    </td>
                </tr>
                
                <{include file="tpl/send_item.tpl"}>  
            </table>
            
            <{include file="tpl/goods_search.tpl"}>
  
        </div>

        <div class="box-footer">
        	<a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
            <button type="submit" name="sub" class="btn btn-default pull-right"><i class="fa fa-paper-plane-o"></i> 申请</button>
            <div style="clear: both;"></div>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(function(){
    	$(".time").datetimepicker({
            format: 'yyyy-mm-dd',
            datemode: 'dmUpDown',
            fontAwesome: true,
            todayBtn:  true,
            todayHighlight: true,
            autoclose: true,
            startView: 2,
            minView: 2
        });
        
    	$("#ban-forever").click(function(){
            var timeInput = $(this).closest('td').find('.time');
            if($(this).is(":checked")){
                timeInput.prop('disabled', true);
            }else{
                timeInput.prop('disabled', false);
            }
        });
    	
        
        
        var nameflag = true;
        var idflag = true;
        var numberflag = true;
        var checkrolename = true;
        $('button[name="sub"]').click(function(){      	
        	var special_id = $('select[name="special_id"]').val();
        	if(special_id == ''){
        		layer.alert('请选择专服', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var server_id = $('select[name="server_id"]').val();
        	if(server_id == ''){
        		layer.alert('请选择服务器', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var role_name = $('input[name="role_name"]').val();
        	if(role_name == ''){
        		layer.alert('请填写角色名', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var role_id = $('input[name="role_id"]').val();
        	if(role_id == ''){
        		layer.alert('请填写角色ID', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var account = $('input[name="account"]').val();
        	if(account == ''){
        		layer.alert('请填写账号', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var real_name = $('input[name="real_name"]').val();
        	if(real_name == ''){
        		layer.alert('请填写真实名字', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var position = $('input[name="position"]').val();
        	if(position == ''){
        		layer.alert('请填写职位', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}         
            
            if(!$("#ban-forever").is(":checked") && $('input[name="ban_date"]').val() == ''){
            	layer.alert('请选择截止日期', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
        	
        	var trade_gold = $('input[name="trade_gold"]').val();
        	if(trade_gold == ''){
        		layer.alert('请填写交易元宝数', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	$('input[name="item_name[]"]').each(function (i){
        		if($(this).val() == ''){
        			nameflag = false;
        		}else{
        			nameflag = true;
        		}
            });
            
            if(!nameflag){
            	layer.alert('请填写道具名称', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }

            $('input[name="item_id[]"]').each(function (i){
        		if($(this).val() == ''){
        			idflag =  false;
        		}else{
        			idflag = true;
        		}
            });
            
            if(!idflag){
            	layer.alert('请填写道具ID', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
            
            $('input[name="item_number[]"]').each(function (i){
            	var max_overlap = $(this).attr('data-max');
            	_sthis = $(this);
		        var num = $(this).val();
        		if($(this).val() == ''){
        			numberflag = false;
        		}else if(parseInt(num) > parseInt(max_overlap)){
        			_sthis.val(max_overlap);
        		}else{
        			numberflag = true;
        		}
            });
            
            if(!numberflag){
            	layer.alert('请填写道具数量', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
            
            var g = $("input[name='g']").val();
            var url ="?r=insidePlayer/checkRole&g="+g;
            //检查角色是否存在
            $.ajax({
    			type : 'POST',
    			url : url,
    			async:false, 
				data : {'roleId':role_name,'server':server_id,'type':1},
				dataType :'json',
				success : function(res){
					if(res.status == 0){
						checkrolename = false;
					}else{
						checkrolename = true;
					}
				}
			});
			if(!checkrolename){
            	layer.alert('角色不存在', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
           
            //return false;
        });
    });
</script>


<script>
	$(function(){
		$('select[name="special_id"]').change(function(){
			var special_id = $(this).val();
			if(special_id == ''){
				var option = '';	
				option += "<option value=''>请选择</option>";
				$('select[name="server_id"]').empty();
				$('select[name="server_id"]').append(option);
				return false;
			}
			var g = $("input[name='g']").val();
			var url = '/oss/?r=channel/getServerForSpecial&g='+g;
			$.ajax({
    		    type : 'POST',
    		    url : url,
			    data : {'special_id':special_id},
			    dataType :'JSON',
			    success : function(res){
				    if(res.status == 1){
					    var option = '';	
					    option += "<option value=''>请选择</option>";
					    for (var i=0;i<res.data.length;i++){
						    option += "<option value='"+res.data[i]['server_id']+"'>"+res.data[i]['server_name']+"</option>";
					    }						

					    $('select[name="server_id"]').empty();
					    $('select[name="server_id"]').append(option);

				    }else{
					    $('select[name="server_id"]').empty();
				    }
			    }
		    });	
		});
	});
</script>


<script>
	$(function(){
		$("#check_role").click(function(){
			var server = $("#server_id").val();
			var type = 1;
			var roleId = $("#role_name").val();
			var g = $("input[name='g']").val();
			if(server == ''){
				layer.alert('请先选择服务器', {icon: 2, skin: 'layui-layer-molv'});
				return false;
			}
			if(roleId == ''){
				layer.alert('请填写角色名', {icon: 2, skin: 'layui-layer-molv'});
				return false;
			}
			var url ="?r=insidePlayer/checkRole&g="+g;
			ajax(url,roleId,server,type);
		});
	
	});
	function ajax(url,roleId,server,type){
    		$.ajax({
    			type : 'POST',
    			url : url,
				data : {'roleId':roleId,'server':server,'type':type},
				dataType :'json',
				success : function(res){
					if(res.status == 1){
						layer.alert('该角色存在', {icon: 1, skin: 'layui-layer-molv'});
					}else{
						layer.alert('该角色不存在', {icon: 2, skin: 'layui-layer-molv'});
					}
				}
			});
    }
</script>

